Skip to content

Conversation

jviau
Copy link
Contributor

@jviau jviau commented Sep 25, 2025

Issue describing the changes in this PR

resolves #11364

Pull request checklist

IMPORTANT: Currently, changes must be backported to the in-proc branch to be included in Core Tools and non-Flex deployments.

  • Backporting to the in-proc branch is not required
    • Otherwise: Link to backporting PR
  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes should not be added to the release notes for the next release
    • Otherwise: I've added my notes to release_notes.md
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • My changes do not require diagnostic events changes
    • Otherwise: I have added/updated all related diagnostic events and their documentation (Documentation issue linked to PR)
  • I have added all required tests (Unit tests, E2E tests) -- TODO

Additional information

This PR adds an app insights telemetry module which exports Meter API instruments to app insights.

Co-pilot summary

This pull request introduces a new system for exporting .NET Meter API metrics to Application Insights, allowing for improved observability of metrics in Azure Functions. The main changes include implementing a custom metric exporter, configuration options, and integration into the application's dependency injection setup. Additionally, supporting extensions and utility methods were added to ensure smooth operation and graceful shutdown.

Metrics Exporter Integration:

  • Added ApplicationInsightsMetricExporter, a custom ITelemetryModule that listens to .NET Meter API instruments and exports their metrics to Application Insights. It handles various numeric types and supports asynchronous collection and graceful shutdown.
  • Introduced ApplicationInsightsMetricExporterOptions for configuring which meters to listen to and the collection interval, with support for future extensibility.
  • Integrated the new metric exporter into the DI container in ScriptHostBuilderExtensions, registering the exporter and configuring it to listen to the core Functions meter.

Telemetry and Utility Enhancements:

  • Added TelemetryClientExtensions to efficiently map Meter instruments and their tags to Application Insights metrics, handling up to 10 dimensions and avoiding unnecessary allocations.
  • Implemented CancellationExtensions to safely cancel CancellationTokenSource instances, handling disposed exceptions gracefully, which is used for robust exporter shutdown.

Dependency and Usability Updates:

  • Updated using statements and minor method signature changes in ScriptHostBuilderExtensions to support the new metrics exporter integration. [1] [2] [3]

These changes collectively enable first-class support for exporting custom and built-in .NET metrics to Application Insights, improving monitoring and diagnostics for Azure Functions.

@jviau jviau requested a review from a team as a code owner September 25, 2025 18:31
@Copilot Copilot AI review requested due to automatic review settings September 25, 2025 18:31
@jviau jviau changed the title U/jviau/app insights meter listener Add AppInsights module to publish meters as metrics Sep 25, 2025
@jviau jviau changed the title Add AppInsights module to publish meters as metrics Add AppInsights module to publish metrics Sep 25, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces Application Insights metric exporting for .NET Meter API instruments in Azure Functions, enabling improved observability by allowing custom and built-in metrics to be exported to Application Insights for monitoring and diagnostics.

  • Adds a custom ApplicationInsightsMetricExporter that listens to .NET Meter API instruments and exports their metrics to Application Insights
  • Implements configuration options and utility extensions for robust metric collection and graceful shutdown handling
  • Integrates the metric exporter into the dependency injection setup with configuration for the core Functions meter

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
ScriptHostBuilderExtensions.cs Adds DI registration for the metric exporter and configures it to listen to the Functions meter
ApplicationInsightsMetricExporter.cs Core exporter implementation that listens to Meter API instruments and exports to Application Insights
ApplicationInsightsMetricExporterOptions.cs Configuration options for specifying which meters to monitor and collection intervals
TelemetryClientExtensions.cs Extension methods for efficiently mapping Meter instruments to Application Insights metrics with dimension handling
CancellationExtensions.cs Utility methods for safe cancellation token handling during shutdown

@jviau jviau force-pushed the u/jviau/app-insights-meter-listener branch from 6cdea89 to d6c4fdc Compare October 1, 2025 16:41
@jviau jviau requested a review from RohitRanjanMS October 2, 2025 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HealthChecks] Publish health check metrics to legacy AppInsights SDK
2 participants